﻿using System;
using System.IO;
using System.Xml;

namespace IdmlSharp
{

	/// <summary>
	/// 
	/// </summary>
	internal abstract class XmlReader : IDisposable
	{

		#region Fields

		/// <summary>
		/// 
		/// </summary>
		private Stream _input;

		#endregion

		#region Constructors

		/// <summary>
		/// 
		/// </summary>
		/// <param name="input"></param>
		protected XmlReader(Stream input)
		{
			this._input = input;
		}

		#endregion

		#region Methods

		/// <summary>
		/// 
		/// </summary>
		/// <param name="callbacks"></param>
		internal void Read(XmlReadingEventHandler handler)
		{
			using (XmlTextReader reader = new XmlTextReader(this._input))
			{
				while (reader.Read())
				{
					switch (reader.NodeType)
					{
						case XmlNodeType.Element: handler.OnElementStart(this, new XmlReadingEventArgs(reader)); break;
					}
				}
			}
		}

		#region IDisposable メンバー

		public void Dispose()
		{
			if (this._input != null)
			{
				this._input.Close();
			}
		}

		#endregion

		#endregion

	}
}
